import java.util.Scanner;

public class Text3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n == 1){
            System.out.println(1);
            return;
        }

        for(int i = n-1 ; i > 0;i--){
            int tmp = 0;
            for(int j = 1; j < i; j++){
                if(i % j == 0){
                    tmp += j;
                }
            }
            if(tmp == n){
                System.out.println(i);
                return;
            }
        }

        System.out.println(-1);
    }
}
